package com.briup.day25;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class Test_ReverSocket {
    public static void main(String[] args) throws Exception {
        //1.创建客户端对象
        Socket socket = new Socket("127.0.0.1",8889);
        System.out.println("客户端发送成功");
        //2.创建io流
        InputStream is = socket.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        OutputStream os = socket.getOutputStream();
        PrintStream pw = new PrintStream(os);
        Scanner sc=new Scanner(System.in);
        System.out.println("请发送一行数据");
        String line;
        while (true) {
            line= sc.nextLine();
            pw.println(line);
            System.out.println("数据发送成功");
            if("quit".equals(line)){//输入quit结束
                break;
            }
            line = br.readLine();//：客户端的输入流（InputStream）是专门用于接收服务器发送过来的数据的通道。
            //
            System.out.println("读取服务器的数据"+line);
        }
        pw.close();
        br.close();
        socket.close();

    }
}
